﻿package mortal.game.view.skill
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.utils.*;
    import extend.language.*;
    import mortal.game.cache.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.view.common.util.*;
    import mortal.game.view.systemSetting.*;

    public class SkillInfo extends ModelInfo
    {
        private var _bagPos:int;
        private var _position:int;
        public var tSkill:TSkill;
        public var learned:Boolean = false;
        private var _preLearned:Boolean;
        private var _nextSkill:TSkill;
        private var _getBookInfos:Array;
        private var _cdDt:Date;
        private var _distance:int;
        public var quickView:Boolean;
        private var _runeLeadCount:int = 0;
        private var _runeAddCD:int = 0;
        private var _shengeAddCD:int = 0;

        public function SkillInfo()
        {
            this._cdDt = new Date();
            return;
        }// end function

        public function get suitId() : int
        {
            if (this.tSkill == null)
            {
                return 0;
            }
            return int(this.tSkill.consumeMaterial);
        }// end function

        public function get autoUse() : Boolean
        {
            if (this.tSkill == null || this.tSkill.posType > 20 || this.tSkill.posType < 0)
            {
                return true;
            }
            return !ClientSetting.local.getIsDone(IsDoneType.SkillAutoSelectStart + this.tSkill.posType - 1);
        }// end function

        public function set runeAddCD(param1:int) : void
        {
            if (this._runeAddCD == param1)
            {
                return;
            }
            this._runeAddCD = param1;
            GameController.cd.registerSkillCD(this);
            return;
        }// end function

        public function set shengeAddCD(param1:int) : void
        {
            if (this._shengeAddCD == param1)
            {
                return;
            }
            this._shengeAddCD = param1;
            GameController.cd.registerSkillCD(this);
            return;
        }// end function

        public function get runeLeadCount() : int
        {
            return this._runeLeadCount;
        }// end function

        public function set runeLeadCount(param1:int) : void
        {
            this._runeLeadCount = param1;
            return;
        }// end function

        public function set preLearned(param1:Boolean) : void
        {
            this._preLearned = param1;
            return;
        }// end function

        public function get leadCountTotal() : int
        {
            if (this.tSkill == null)
            {
                return this._runeLeadCount;
            }
            return this._runeLeadCount + this.tSkill.leadCount;
        }// end function

        public function get isComboSkill() : Boolean
        {
            if (this.tSkill == null || this.tSkill.combo == null || this.tSkill.combo.length < 5)
            {
                return false;
            }
            return true;
        }// end function

        public function get preLearned() : Boolean
        {
            var _loc_1:Array = null;
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            if (this.tSkill.preSkills == null || this.tSkill.preSkills == "")
            {
                return true;
            }
            _loc_1 = this.tSkill.preSkills.split("#");
            _loc_2 = 0;
            while (_loc_2 < _loc_1.length)
            {
                
                _loc_3 = int(_loc_1[_loc_2]);
                _loc_2++;
            }
            return this._preLearned;
        }// end function

        public function get nextSkill() : TSkill
        {
            if (this._nextSkill == null)
            {
                if (this.isMaxLevel())
                {
                    return null;
                }
                this._nextSkill = SkillConfig.instance.getSkillByLevel(this.tSkill.series, (this.tSkill.skillLevel + 1));
            }
            return this._nextSkill;
        }// end function

        public function get maxLevel() : int
        {
            return SkillConfig.instance.getMaxLevelBySerialId(this.tSkill.series);
        }// end function

        public function isMaxLevel() : Boolean
        {
            return this.maxLevel == this.tSkill.skillLevel;
        }// end function

        public function get preSkill() : TSkill
        {
            if (this.tSkill.preSkills != null && this.tSkill.preSkills != "")
            {
                return SkillConfig.instance.getInfoById(int(this.tSkill.preSkills));
            }
            return null;
        }// end function

        public function get getBookInfos() : Array
        {
            return this._getBookInfos;
        }// end function

        public function get position() : int
        {
            if (this.tSkill && this.tSkill.posType > 0)
            {
                return this.tSkill.posType;
            }
            return this._position;
        }// end function

        public function set position(param1:int) : void
        {
            this._position = param1;
            return;
        }// end function

        public function set bagPos(param1:int) : void
        {
            this._bagPos = param1;
            return;
        }// end function

        public function get bagPos() : int
        {
            return this._bagPos;
        }// end function

        public function get skillLevel() : int
        {
            if (this.tSkill)
            {
                return this.tSkill.skillLevel;
            }
            return 0;
        }// end function

        public function get levelLimited() : int
        {
            if (this.tSkill)
            {
                return this.tSkill.levelLimit;
            }
            return 0;
        }// end function

        public function get skillCareer() : int
        {
            if (this.tSkill)
            {
                return SkillUtil.getCarrer(this.tSkill);
            }
            return 0;
        }// end function

        public function set cdDt(param1:Date) : void
        {
            this._cdDt = param1;
            return;
        }// end function

        public function get cdDt() : Date
        {
            return this._cdDt;
        }// end function

        public function updateGetBookInfo() : void
        {
            if (this.learned)
            {
                if (this._getBookInfos != null)
                {
                    this._getBookInfos.splice(0);
                }
                return;
            }
            if (!this._getBookInfos)
            {
                this._getBookInfos = [];
            }
            return;
        }// end function

        public function upgradable() : Boolean
        {
            if (Cache.instance.skill.isDebugLearn)
            {
                return true;
            }
            if (!this.learned)
            {
                return false;
            }
            if (this.isMaxLevel())
            {
                return false;
            }
            if (!this.isLevelEnough())
            {
                return false;
            }
            if (!this.isCoinEnough())
            {
                return false;
            }
            if (!this.isSkillPointEnough())
            {
                return false;
            }
            if (this.isEquipSkill)
            {
                if (!this.isSkillBookEnough(this.nextSkill))
                {
                    return false;
                }
            }
            return true;
        }// end function

        public function isLevelEnough(param1:TSkill = null) : Boolean
        {
            if (param1 == null)
            {
                param1 = this.nextSkill;
            }
            if (param1 && param1.levelLimit > Cache.instance.role.entityInfo.level)
            {
                return false;
            }
            return true;
        }// end function

        public function isSkillPointEnough(param1:TSkill = null) : Boolean
        {
            if (param1 == null)
            {
                param1 = this.nextSkill;
            }
            if (param1 && param1.needSkillPoint > Cache.instance.login.loginGame.money.skillPoint)
            {
                return false;
            }
            return true;
        }// end function

        public function isCoinEnough(param1:TSkill = null) : Boolean
        {
            if (param1 == null)
            {
                param1 = this.nextSkill;
            }
            if (param1 && param1.needCoin > Cache.instance.login.loginGame.money.coin + Cache.instance.login.loginGame.money.coinBind)
            {
                return false;
            }
            return true;
        }// end function

        public function isSkillBookEnough(param1:TSkill = null) : Boolean
        {
            var _loc_2:ItemInfo = null;
            if (param1 == null)
            {
                param1 = this.tSkill;
            }
            if (param1 == null)
            {
                return false;
            }
            if (param1.needSkillBook > 0)
            {
                _loc_2 = ItemConfig.instance.getConfig(param1.needSkillBook);
                if (Cache.instance.pack.backPackCache.getItemByCode(_loc_2.code) == null && Cache.instance.pack.backPackCache.getItemByCode(_loc_2.codeUnbind) == null)
                {
                    return false;
                }
            }
            return true;
        }// end function

        public function learnable() : Boolean
        {
            var _loc_1:EquipmentSuitData = null;
            var _loc_2:int = 0;
            var _loc_3:AttributeData = null;
            if (Cache.instance.skill.isDebugLearn)
            {
                return true;
            }
            if (this.learned || !this.preLearned)
            {
                return false;
            }
            if (!this.isLevelEnough(this.tSkill))
            {
                return false;
            }
            if (!this.isCoinEnough(this.tSkill))
            {
                return false;
            }
            if (!this.isSkillPointEnough(this.tSkill))
            {
                return false;
            }
            if (!this.isSkillBookEnough())
            {
                return false;
            }
            if (this.isEquipSkill)
            {
                _loc_1 = EquipmentUtil.getEquipmentSuitData(this.suitId, Cache.instance.role.entityInfo.career, EColor._EColorGold);
                _loc_2 = 0;
                while (_loc_2 < _loc_1.parts.length)
                {
                    
                    _loc_3 = _loc_1.parts[_loc_2];
                    if (_loc_3.type == 0)
                    {
                        return false;
                    }
                    _loc_2++;
                }
            }
            return true;
        }// end function

        public function get isEquipSkill() : Boolean
        {
            if (this.tSkill == null)
            {
                return false;
            }
            if (this.tSkill.posType >= 200 && this.tSkill.posType <= 299)
            {
                return true;
            }
            return false;
        }// end function

        public function get isBeAttackSkill() : Boolean
        {
            if (this.tSkill == null)
            {
                return false;
            }
            return this.tSkill.triggerType == ESkillTriggType._ESkillTriggBeAttack || this.tSkill.triggerType == ESkillTriggType._ESkillTriggBorn;
        }// end function

        public function get isCareerSkill() : Boolean
        {
            if (this.tSkill == null)
            {
                return false;
            }
            if (this.tSkill.posType >= 1 && this.tSkill.posType <= 20)
            {
                return true;
            }
            return false;
        }// end function

        private function getBaseInfo(param1:TSkill) : String
        {
            var _loc_3:String = null;
            var _loc_4:int = 0;
            var _loc_2:String = "";
            return _loc_2;
        }// end function

        private function getEffectInfo(param1:TSkill) : String
        {
            var _loc_2:String = "";
            return _loc_2;
        }// end function

        private function learnInfo() : String
        {
            var _loc_1:String = "";
            if (this.nextSkill.levelLimit > Cache.instance.role.entityInfo.level)
            {
                _loc_1 = _loc_1 + (HTMLUtil.addColor(Language.getString(20221) + "：" + this.nextSkill.levelLimit, "#ff1414") + "<br>");
            }
            if (this.nextSkill.needCoin > Cache.instance.login.loginGame.money.coin && this.nextSkill.needCoin > Cache.instance.login.loginGame.money.coinBind)
            {
                _loc_1 = _loc_1 + (HTMLUtil.addColor(Language.getString(20223) + "：" + this.nextSkill.needCoin, "#ff1414") + "<br>");
            }
            if (!this.preLearned && this.preSkill != null)
            {
                _loc_1 = _loc_1 + (HTMLUtil.addColor(Language.getString(20224) + "：" + this.preSkill.name, "#ff1414") + "<br>");
            }
            return _loc_1;
        }// end function

        private function getBaseEffect(param1:int) : String
        {
            var _loc_2:* = Language.getString(20225);
            if (this.tSkill.type == ESkillType._ESkillTypeCure)
            {
                _loc_2 = Language.getString(20226);
            }
            return HTMLUtil.addColor(Language.getString(20227) + _loc_2 + "：" + param1 + "%", "#f5ff00");
        }// end function

        private function getAddEffect(param1:int) : String
        {
            return "";
        }// end function

        public function getUseType(param1:Boolean = true) : String
        {
            return "...";
        }// end function

        public function get dragAble() : Boolean
        {
            if (this.quickView)
            {
                return false;
            }
            if (this.tSkill)
            {
                return true;
            }
            return false;
        }// end function

        public function get distance() : int
        {
            return this.tSkill.distance + this._distance;
        }// end function

        public function get attackDisStr() : String
        {
            var _loc_1:* = this.tSkill.distance.toString();
            if (this._distance != 0)
            {
                _loc_1 = _loc_1 + this.getRuneStr(this._distance);
            }
            return _loc_1;
        }// end function

        public function get magicNeed() : int
        {
            if (this.tSkill)
            {
                return this.tSkill.consume;
            }
            return 0;
        }// end function

        public function get skillId() : int
        {
            if (this.tSkill)
            {
                return this.tSkill.skillId;
            }
            return 0;
        }// end function

        public function get skillType() : int
        {
            if (this.tSkill)
            {
                return this.tSkill.type;
            }
            return 0;
        }// end function

        public function get useType() : int
        {
            if (this.tSkill)
            {
                return this.tSkill.type;
            }
            return 0;
        }// end function

        public function get leadTime() : int
        {
            if (this.tSkill)
            {
                return this.tSkill.leadTime;
            }
            return 0;
        }// end function

        public function get leadCount() : int
        {
            if (this.tSkill)
            {
                return this.tSkill.leadCount;
            }
            return 0;
        }// end function

        public function get cooldownTime() : int
        {
            return this._runeAddCD + this._shengeAddCD + this.tSkill.cooldownTime;
        }// end function

        public function getCoolDownSeconds(param1:Boolean = false) : String
        {
            var _loc_2:* = this.cooldownTime;
            if (!param1)
            {
                _loc_2 = this.tSkill.cooldownTime;
            }
            if (_loc_2 % 1000 == 0)
            {
                return int(_loc_2 / 1000).toString();
            }
            return (_loc_2 / 1000).toFixed(1);
        }// end function

        public function get cooldownTimeStr() : String
        {
            var _loc_1:* = Number(this.tSkill.cooldownTime / 1000).toString() + Language.getString(20693);
            if (this._runeAddCD != 0)
            {
                _loc_1 = _loc_1 + (this.getRuneStr(Number(this._runeAddCD / 1000)) + HTMLUtil.addColor(Language.getString(20693), "#FEAE58"));
            }
            if (this._shengeAddCD != 0)
            {
                _loc_1 = _loc_1 + (this.getShengeStr(Number(this._shengeAddCD / 1000)) + HTMLUtil.addColor(Language.getString(20693), "#FEAE58"));
            }
            return _loc_1;
        }// end function

        public function get skillName() : String
        {
            if (this.tSkill)
            {
                return this.tSkill.name;
            }
            return "";
        }// end function

        public function getRuneStr(param1:Number, param2:String = "#FEAE58") : String
        {
            if (param1 > 0)
            {
                return HTMLUtil.addColor(Language.getStringByParam(21090, param1), param2);
            }
            return HTMLUtil.addColor(Language.getStringByParam(21091, -param1), param2);
        }// end function

        public function getShengeStr(param1:Number, param2:String = "#FEAE58") : String
        {
            if (param1 > 0)
            {
                return HTMLUtil.addColor(Language.getStringByParam(21092, param1), param2);
            }
            return HTMLUtil.addColor(Language.getStringByParam(21093, -param1), param2);
        }// end function

        public function isRuneBelongsToMe(param1:TRune) : Boolean
        {
            return SkillUtil.isRuneBelongsToSkill(param1, this.tSkill);
        }// end function

    }
}
